package Version3;

import java.io.IOException;
import java.io.InputStream;

public class Request {
    private String method;
    private String url;
    private InputStream inputStream;

    public Request() {
    }

    public Request(InputStream inputStream) throws IOException {
        this.inputStream = inputStream;

        //从InputSteam中获取 method和url
        int count = 0;
        while (count == 0) {
            count = this.inputStream.available();
        }

        //byte数组
        byte[] bytes = new byte[count];

        //从流中读取数据到 byte数组中
        inputStream.read(bytes);

        //构建字符串
        String inputStr = new String(bytes);

        //根据回车进行分割
        String firstLine = inputStr.split("\\n")[0];
        String[] strings = firstLine.split(" ");
        this.method = strings[0];
        this.url = strings[1];

        System.out.println("====>" + this.method);
        System.out.println("====>" + this.url);

    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public InputStream getInputStream() {
        return inputStream;
    }

    public void setInputStream(InputStream inputStream) {
        this.inputStream = inputStream;
    }
}
